package com.sz.myinterface;


import com.aliyun.api.gateway.demo.util.HttpUtils;
import com.sz.utils.CodeUtils;
import org.apache.http.HttpResponse;

import java.util.HashMap;
import java.util.Map;

public class SMSCode {


    public static String sendSMS(String phone){
        String host = "https://gyytz.market.alicloudapi.com";
        String path = "/sms/smsSend";
        String method = "POST";
        String appcode = "045ca0303c534d55bec9100912040eb5";//个人code阿里云
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("mobile", phone);//手机号
        //获取验证码
        String code=CodeUtils.getSixRandom();
        String param = CodeUtils.getCode(code);
        querys.put("param",param);//**code**:348468,**minute**:1
        querys.put("smsSignId", "2e65b1bb3d054466b82f0c9d125465e2");
        querys.put("templateId", "908e94ccf08b4476ba6c876d13f084ad");
        Map<String, String> bodys = new HashMap<String, String>();

        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            System.out.println(response.toString());
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }

        return code;
    }

    public static void main(String[] args) {
        SMSCode smsCode=new SMSCode();

        smsCode.sendSMS("13726695562");

    }

}
